package com.mindao.app.site.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jfinal.weixin.sdk.api.JsTicket;
import com.jfinal.weixin.sdk.api.JsTicketApi;
import com.mindao.app.common.spring.controller.BaseBaseController;
import com.mindao.app.weixin.conf.WxmpAccount;
import com.mindao.utils.config.EaCommonUtils;
import com.mindao.utils.hardinfo.HardInfo;
import com.tencent.utils.WxJsSignUtils;

/**
/* 版权所有： 广州敏道科技有限公司
/*
/* 功能描述：微信SDK/微信UI
/*
/* 创 建 人：李国才
/* 创建时间：2016年7月10日 上午6:36:45 	
 **/
@Controller
@RequestMapping("/site/sitewx")
public class SiteWxController extends BaseBaseController{
	@Autowired
	protected WxmpAccount wxmpAccount ;
	/**
	 * 进入微信SDK
	 * @param request
	 * @param response
	 * @param session
	 * @param rhs
	 * @param uuid
	 * @return
	 * @throws Exception
	 */
	@RequestMapping 
	public String wxsdk(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs ,String uuid ) throws Exception {
		//调用微信JS-SDK，首先得到jsapi_ticket，jsapi_ticket是公众号用于调用微信JS接口的临时票据。js的config初始化方法用到
		JsTicket jsTicket =JsTicketApi.getTicket(JsTicketApi.JsApiType.jsapi);
		String url=request.getRequestURL().toString();
		Map configMap=WxJsSignUtils.getConfigSign(jsTicket.getTicket(), url );
		configMap.put("appId", wxmpAccount.getWxAppId());
		System.out.println(configMap);
		rhs.addAttribute("configMap",configMap);
		return super.rtnDefault(request, response, session, rhs);
	}

    /**
     * weui进入二维码页面
     * @author liguocai
     *
     */
	@RequestMapping 
	public String qrcodeWeui(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs ,String uuid ) throws Exception {
		return super.rtnDefault(request, response, session, rhs);
	}
    /**
     * weui显示二维码
     * @author liguocai
     *
     */
	@RequestMapping 
	public void qrcodeWeuiShow(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs ,String uuid ) throws Exception {
		String serverPath ="http:/"+HardInfo.findNonLocalhostIp()+":"+request.getLocalPort()+request.getContextPath();
		String url=serverPath+"/common/weui/example/index.html";
		System.out.println(url);
		EaCommonUtils.genQrcode(response, url);
		//return super.rtnDefault(request, response, session, rhs);
	}
	
}
